﻿using SnakeGame.Lesson1;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SnakeGame.Lesson2
{
    internal class DifficultySelect : ISceneUpdate
    {
        protected int nowSceneIndex = 0;
        protected string title = "Difficulty";
        protected string Easy = "Easy";
        protected string Medium = "Medium";
        protected string Hard = "Hard";
        protected string Crazy = "Crazy";
        public void Update()
        {
            // 开始和结束场景的更新逻辑
            // 设置字体颜色
            Console.ForegroundColor = ConsoleColor.White;
            // 显示标题
            Console.SetCursorPosition(Game.width / 2 - title.Length / 2, 5);
            Console.Write(title);
            // 显示简单难度选项
            Console.SetCursorPosition(Game.width / 2 - Easy.Length / 2, 8);
            Console.ForegroundColor = nowSceneIndex == 0 ? ConsoleColor.Green : ConsoleColor.White;
            Console.Write(Easy);
            // 显示中等难度选项
            Console.SetCursorPosition(Game.width / 2 - Medium.Length / 2, 11);
            Console.ForegroundColor = nowSceneIndex == 1 ? ConsoleColor.Green : ConsoleColor.White;
            Console.Write(Medium);
            // 显示困难难度选项
            Console.SetCursorPosition(Game.width / 2 - Hard.Length / 2, 14);
            Console.ForegroundColor = nowSceneIndex == 2 ? ConsoleColor.Green : ConsoleColor.White;
            Console.Write(Hard);
            // 显示疯狂难度选项
            Console.SetCursorPosition(Game.width / 2 - Crazy.Length / 2, 17);
            Console.ForegroundColor = nowSceneIndex == 3 ? ConsoleColor.Green : ConsoleColor.White;
            Console.Write(Crazy);
            // 显示下方的选项
            Console.SetCursorPosition(Game.width / 2 - 2, 20);
            Console.ForegroundColor = nowSceneIndex == 4 ? ConsoleColor.Red : ConsoleColor.White;
            Console.Write("Back →");

            // 检测输入
            switch (Console.ReadKey(true).Key)
            {
                case ConsoleKey.W:
                    nowSceneIndex--;
                    if (nowSceneIndex < 0)
                    {
                        nowSceneIndex = 4; // 循环到最后一个选项
                    }
                    break;

                case ConsoleKey.S:
                    nowSceneIndex++;
                    if (nowSceneIndex > 4)
                    {
                        nowSceneIndex = 0; // 循环到第一个选项
                    }
                    break;

                case ConsoleKey.Enter:
                    Game.SelectDifficulty(nowSceneIndex);
                    break;
            }
        }
    }
}
